﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Lab1
{
    public class RecommendationService
    {
        private DatabaseEntities db = new DatabaseEntities();
        public IEnumerable<Recommendation> getAll()
        {
            List<Recommendation> list= (from t in db.Recommendation
                    select t).ToList();
  
            return list;
        }
        public void update(Recommendation model)
        {

            using (DatabaseEntities context = new DatabaseEntities())
            {
                var original = (from t in context.Recommendation
                                where t.Id.Equals(model.Id)
                                select t).SingleOrDefault();
                context.Recommendation.ApplyCurrentValues(model);
                context.SaveChanges();
            }

        }
        public void delete(Recommendation model)
        {
            using (DatabaseEntities context = new DatabaseEntities())
            {
                var original = (from t in context.Recommendation
                                where t.Id.Equals(model.Id)
                                select t).SingleOrDefault();
                context.DeleteObject(original);
                context.SaveChanges();
            }
        }
        public void save(Recommendation model)
        {
            db.AddToRecommendation(model);
            db.SaveChanges();
        }

        public Recommendation getById(Guid id)
        {
            Recommendation model= (from t in db.Recommendation
                    where t.Id.Equals(id)
                    select t).Single<Recommendation>();
      
            return model;
        }
    }
}
